package cn.edu.experiment3.entity;

import java.util.ArrayList;
import java.util.List;
import cn.edu.experiment3.base.Person;

public class Teacher extends Person {
    private final List<Course> taughtCourses = new ArrayList<>();

    public Teacher(String id, String name) {
        super(id, name);
    }

    /* 供外部获取姓名 */
    public String getName() { return name; }

    /* 开课：把课程挂到自己名下，并加入教师课表 */
    public void openCourse(Course c) {
        c.setTeacher(this);
        taughtCourses.add(c);
        System.out.println("教师 " + name + " 开课：" + c.getName());
    }

    /* 覆写：打印教师课表（工作单） */
    @Override
    public void printSchedule() {
        System.out.println("========== 教师个人课表 ==========");
        System.out.println("编号：" + id);
        System.out.println("姓名：" + name);
        if (taughtCourses.isEmpty()) {
            System.out.println("暂无开课信息");
            return;
        }
        System.out.println("所开课程：");
        for (Course c : taughtCourses) {
            System.out.printf("  %s | %s | %s%n",
                    c.getName(), c.getLocation(), c.getTime());
        }
    }
}